<style lang='less' scoped>
  @import '~style/filter.less';

  .dataBox{
    margin-top: 20px;
    text-align: center;
  }

  .paginationBox{
    float: right;
    margin-top: 20px;
  }

</style>

<template>
  <div id='appointmentList'>

    <list-params
      v-show='this.$route.name == "appointmentList"'
      v-on:setFilterParams='setAjaxParams'
      v-on:exportExcel='exportExcel'
      :getButtonConfig='getButtonConfig'
      :reservationRecordType='reservationRecordType'
    >
    </list-params>



    <list-result
      v-show='this.$route.name == "appointmentList"'
      :data='data'
      :totalSize='totalSize'
      :getButtonConfig='getButtonConfig'
      :reservationRecordType='reservationRecordType'
      v-on:setTableParams='setAjaxParams'
    >

    </list-result>

  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { getList,getExcelList,getRecordStatus} from 'api/transactionManagement/index.js'
  import listParams from './listParams.vue'
  import listResult from './listResult.vue'

  export default {
    components:{
      listParams,
      listResult
    },
    data(){
      return{
        reservationRecordType:[],//发行方
        formQueryData:{
          orderBy:'id',
          xsc:'DESC',
        },
        createionTimeArr:null,//选择的创建起止时间
        data:[],//查询回来的数据
        totalSize:0,//总条数
        currentPage:1,//当前页
        pageSize:20,//每页显示的条数
      }
    },
    computed:{
      getButtonConfig(){
        return this.$store.getters.getButtonConfig('appointmentList')
      },
    },
    
    methods:{
      setAjaxParams(e){
        // console.log('setAjaxParams', e, this.formQueryData)
        Object.assign(this.formQueryData, e)
        this.getList(this.formQueryData)
      },
      async getList(parm){
        try {
          let obj = this.setParams(parm)
          let back = await getList(obj)
          back = back.data
          console.log('查询预约记录列表！', parm, back)
          if (back && back.resultCode == '200') {
            if (back.result) {
              for (let i = 0; i < back.result.length; i++) {
                back.result[i].index = i + 1
              }
            }
            this.data = back.result;
            this.totalSize = back.size;
          }

        } catch (err) {

          this.$alert('查询错误！')
          console.error(err)
        }
      },
      setParams(obj1){//部分请求参数不能传空值！
        let {keys} = Object, params={};
        for(let key of Object.keys(obj1)){
          // console.log(key, obj1[key])
          if(obj1[key]){
            params[key] = obj1[key]
          }
        }
        return params
      },
      async exportExcel(parm){
        try {
          let obj = this.setParams(parm)
          console.log(obj)
          let back = await getExcelList(obj)
          window.location.href=back.request.responseURL;

        } catch (err) {

          this.$alert('查询错误！')
          console.error(err)
        }
      },

      goPage(name, parm={}, query={}){
        // console.log(name)
        this.$router.push({
          name: name,
          params:parm,
          query:query,
        })
      },

      setTitleMsg(msg){
        this.$emit('setTitleMsg', msg)
      },

      async loadStatus(){
        try{
          let back = await getRecordStatus()
          back = back.data;
          console.log('getRecordStatus',back)
          if(back && back.resultCode ==='200'){
            this.reservationRecordType = back.result;
          }else{
            this.$message({
              message: '读取预约状态失败！' + back.msg,
              type: 'warning'
            });
          }
        }catch(err){
          this.$message({
            message: '读取预约状态失败！',
            type: 'warning'
          });
          console.error(err)
        }
      }
    },
    created(){
      this.setTitleMsg(['交易管理', '预约记录'])
      this.loadStatus()
    },
    mounted(){

    },
  }
</script>
